<?php
/**
 * (jobs) 产品提货订单
 */

namespace App\Jobs\ProductPickup;

use App\Models\Product\ProductPackingBox;
use App\Models\Product\ProductSku;
use App\Models\ProductPickup\PickupOrder;
use App\Models\ProductPickup\PickupOrderLog;
use App\Util\SerialNo;
use Encore\Admin\Facades\Admin;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class PickupOrderCreate implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $pickups;

    /**
     * @param $pickups
     */
    public function __construct($pickups)
    {
        $this->pickups = $pickups;
    }

    /**
     * Execute the job.
     * @return void
     */
    public function handle()
    {
        $this->exeFillData($this->pickups);
    }

    private function exeFillData($pickups){

        foreach ($pickups as $pickupSku){

            if($pickupSku->confirm_num > 0){
                $item = [];
                $item['pickup_no'] = SerialNo::getThNo();
                $item['classify_id'] = $pickupSku->classify_id;
                $item['area_id'] = $pickupSku->area_id;
                $item['psku_id'] = $pickupSku->psku_id;
                $item['seller_id'] = $pickupSku->seller_id;
                pickupOrder::query()->create($item);

                ProductPackingBox::query()->where('psku_id', $pickupSku->psku_id)->first();

                $item['month'] = $pickupSku->id;
                $item['plan_num'] = $pickupSku->confirm_num;
                $item['shipping_num'] = $pickupSku->confirm_num;
                $item['shipping_box'] = $pickupSku->confirm_num;
                $item['cycle'] = $pickupSku->id;
                $item['seller_id'] = $pickupSku->id;
                //pickupOrderLog::query()->create($item);
            }
        }
    }

}
